new Vue({
    el: "#app",

    mounted() {
        this.selall();
    },


    methods: {
        selall() {
            axios({
                method: "post",
                url: "/brand/seland?dqys=" + this.currentPage + "&myts=" + this.myts,
                data: this.brand
            }).then((json) => {
                this.tableData = json.data.brands;
                this.count = json.data.pageCount;
            })
        },
        tableRowClassName({row, rowIndex}) {
            if (rowIndex === 1) {
                return 'warning-row';
            } else if (rowIndex === 3) {
                return 'success-row';
            }
            return '';
        },
        // 复选框选中后执行的方法
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 查询方法
        onSubmit() {
            this.selall();
        },
        // 添加数据
        addBrand() {
            axios.post(
                "/brand/add",
                this.brand
            ).then(json => {
                if (json.data) {
                    this.dialogVisible = false;
                    this.selall();
                    this.$message({
                        message: '恭喜你!添加成功!',
                        type: 'success'
                    });
                }
            })
        },

        //删除操作
        delete() {
            this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                axios.post(
                    "/brand/delid",
                    this.delids
                ).then((json) => {
                    if (json.data) {
                        this.selall();
                        this.$message({
                            message: '恭喜你!删除成功!',
                            type: 'success'
                        });
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },

        //删除单个
        delById(row) {
            this.delids[0] = row.id;
            this.delete();
        },

        //批量删除
        deleteByIds() {
            for (let i = 0; i < this.multipleSelection.length; i++) {
                this.delids[i] = this.multipleSelection[i].id
            }
            this.delete();
        },

        //分页
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.selall();
            console.log(`当前页: ${val}`);
        }
        ,
        updById(row) {
            this.brand = row;
            this.updateBrand = true;
        }
        ,
        updBrand() {
            axios.post(
                "/brand/updbyid",
                this.brand
            ).then((data => {
                if (data.data) {
                    this.$message({
                        message: '恭喜你!修改成功!',
                        type: 'success'
                    });
                }
            }))
        }

    },
    data() {
        return {
            //每页条数
            myts: 5,
            //总条数
            count: 0,
            // 当前页码
            currentPage: 1,
            // 添加数据对话框是否展示的标记
            dialogVisible: false,
            //修改数据对话框是否展示标记
            updateBrand: false,
            // 品牌模型数据
            brand: {
                status: '',
                brandName: '',
                companyName: '',
                id: "",
                ordered: "",
                description: ""
            },
            // 复选框选中数据集合
            multipleSelection: [],
            //被选中的数组id
            delids: [],
            // 表格数据
            tableData: []
        }
    }
})